package com.fzy.leetcodeExam.test350;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Main test = new Main();
//        System.out.println(test.distanceTraveled(1, 2));
        System.out.println(test.findValueOfPartition(new int[]{78,36,2,70,64,24,34,63,21,49}));
    }


    public int distanceTraveled(int mainTank, int additionalTank) {
        int distance = 0;

        for(int i = 1;mainTank != 0;i++){
            distance += 10;
            mainTank--;
            if(i%5 ==0 && additionalTank>0){
                mainTank++;
                additionalTank--;
            }
        }
        return distance;

    }

    public int findValueOfPartition(int[] nums) {
        Arrays.sort(nums);

        Set<Integer> set = new HashSet<>();
        for (int num : nums){
            if(set.contains(num)){
                return 0;
            }
            set.add(num);
        }
        int min = Integer.MAX_VALUE;
        int[] arr = new int[nums.length-1];
        for(int i = 0;i<nums.length-1;i++){
            arr[i] = nums[i+1] - nums[i];
            if(arr[i]<min){
                min = arr[i];
            }
        }
        return min;
    }

    private static final int MOD = 1000000007;
    public int specialPerm(int[] nums) {
        Arrays.sort(nums);
        return backtrack(nums,0);
    }

    private int backtrack(int[] nums,int start){
        if(start == nums.length){
            return 1;
        }
        int count = 0;

        for(int i = start;i<nums.length;i++){
            if(start>0 && !isSpecial(nums[start-1],nums[i])){
                continue;
            }
            swap(nums,start,i);
            count += backtrack(nums,start+1);
            swap(nums,start,i);
        }
        return count%MOD;
    }

    private boolean isSpecial(int last,int curr){
        return last % curr == 0 || curr % last == 0;
    }

    private static void swap(int[] nums,int i,int j){
        int t = nums[i];
        nums[i] = nums[j];
        nums[j] = t;
    }
}
